package com.anolesoft.amljmes.fortysix.service.mapper;

import com.anolesoft.amljmes.fortysix.dto.MesBzzPtdDto;
import com.anolesoft.amljmes.fortysix.dto.MesBzzPtdmxDto;
import com.anolesoft.amljmes.fortysix.dto.PtdbsDto;
import com.anolesoft.amljmes.fortysix.dto.PtmlVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AddPtdMapper {
    @Insert("insert into mes_bzz_ptd\n" +
            "  (objuid,\n" +
            "   supporting_order_no,\n" +
            "   order_number,\n" +
            "   batch,\n" +
            "   part_dispatch_number,\n" +
            "   model,\n" +
            "   bom_classification,\n" +
            "   sorties,\n" +
            "   item_no,\n" +
            "   material_name,\n" +
            "   drawing_no,\n" +
            "   quantity,\n" +
            "   demand_time,\n" +
            "   dispatch,\n" +
            "   customer,\n" +
            "   product_type,\n" +
            "   factory_code,\n" +
            "   founder,\n" +
            "   supporting_plan_pk,fathernumber,fathername,danwei,danjishu,proportion,affiliation)\n" +
            "values" +
            "(#{objuid, jdbcType=VARCHAR}," +
            "'PTDH' || to_char(sysdate, 'yyyy-mm-dd') || lpad(seq_ptdh_code.nextval, 4, 0)," +
            "#{orderNumber, jdbcType=VARCHAR}," +
            "#{batch, jdbcType=VARCHAR}," +
            "#{partDispatchNumber, jdbcType=VARCHAR}," +
            "#{model, jdbcType=VARCHAR}," +
            "#{bomClassification, jdbcType=VARCHAR}," +
            "#{sorties, jdbcType=VARCHAR}," +
            "#{itemNo, jdbcType=VARCHAR}," +
            "#{materialName, jdbcType=VARCHAR}," +
            "#{drawingNo, jdbcType=VARCHAR}," +
            "#{quantity, jdbcType=NUMERIC}," +
            "to_date(#{demandTime, jdbcType=DATE},'yyyy-mm-dd')," +
            "#{dispatch, jdbcType=VARCHAR}," +
            "#{customer, jdbcType=VARCHAR}," +
            "#{productType, jdbcType=NUMERIC}," +
            "#{factoryCode, jdbcType=VARCHAR}," +
            "#{founder, jdbcType=VARCHAR}," +
            "#{supportingPlanPk, jdbcType=VARCHAR}," +
            "#{fathernumber, jdbcType=VARCHAR}," +
            "#{fathername, jdbcType=VARCHAR}," +
            "#{danwei, jdbcType=VARCHAR}," +
            "#{danjishu, jdbcType=VARCHAR}," +
            "#{proportion, jdbcType=VARCHAR}," +
            "#{affiliation, jdbcType=VARCHAR})")
    int addPtd(MesBzzPtdDto inFoDtoParam);

    @Insert("insert into mes_bzz_ptdmx\n" +
            "  (item_no,\n" +
            "   part_drawing_no,\n" +
            "   material_type,\n" +
            "   demand_time,\n" +
            "   demand_quantity,\n" +
            "   quantity_of_missing_parts,\n" +
            "   matching_doc_pk,\n" +
            "   factory_code,\n" +
            "   paigonghao,\n" +
            "   jixing,\n" +
            "   jiaofuchejian,\n" +
            "   jieshouchejian,\n" +
            "   jiaofushunxu,serialnumber,name,divisionroute,scheduledstarttime,scheduledendtime,danwei,danjishu,proportion,supplier,affiliation,monumber)\n" +
            "values" +
            "(#{itemNo, jdbcType=VARCHAR}," +
            "#{partDrawingNo, jdbcType=VARCHAR}," +
            "#{materialType, jdbcType=VARCHAR}," +
            "to_date(#{demandTime, jdbcType=DATE},'yyyy-mm-dd')," +
            "#{demandQuantity, jdbcType=NUMERIC}," +
            "#{quantityOfMissingParts, jdbcType=NUMERIC}," +
            "#{matchingDocPk, jdbcType=VARCHAR}," +
            "#{factoryCode, jdbcType=VARCHAR}," +
            "#{paigonghao, jdbcType=VARCHAR}," +
            "#{jixing, jdbcType=VARCHAR}," +
            "#{jiaofuchejian, jdbcType=VARCHAR}," +
            "#{jieshouchejian, jdbcType=VARCHAR}," +
            "#{jiaofushunxu, jdbcType=VARCHAR}," +
            "#{serialnumber, jdbcType=VARCHAR}," +
            "#{name, jdbcType=VARCHAR}," +
            "#{divisionroute, jdbcType=VARCHAR}," +
            "#{scheduledstarttime, jdbcType=VARCHAR}," +
            "#{scheduledendtime, jdbcType=VARCHAR}," +
            "#{danwei, jdbcType=VARCHAR}," +
            "#{danjishu, jdbcType=VARCHAR}," +
            "#{proportion, jdbcType=VARCHAR}," +
            "#{supplier, jdbcType=VARCHAR}," +
            "#{affiliation, jdbcType=VARCHAR}," +
            "#{monumber,jdbcType = VARCHAR})")
    int addPtdmx(MesBzzPtdmxDto inFoDtoParam);

    @Update("update mes_bzz_ptjh set generatematching_document = 1 where objuid = #{objuid, jdbcType=VARCHAR}" )
    int update(String objuid);

    @Select("select t.danwei, t.danjishu, t.chengzhidanwei\n" +
            "  from Mes_bzz_ptml t\n" +
//            " where t.changdaihao = #{changdaihao, jdbcType = VARCHAR}\n" +
            "   where t.jixing = #{jixing, jdbcType = VARCHAR}\n" +
            "   and t.tuhao = #{tuhao, jdbcType = VARCHAR}\n" +
            "   and t.jiaofuchejian = #{jiaofuchejian,jdbcType = VARCHAR}\n" +
            "   and t.jieshouchejian = #{jieshouchejian,jdbcType = VARCHAR}\n" +
            "   and t.futuhao = #{fathernumber,jdbcType = VARCHAR}\n" +
            "   and t.jiaofushunxu = #{jiaofushunxu, jdbcType = VARCHAR}\n")
    PtmlVo queryPtmlInfo(PtmlVo ptmlVo);

    @Select("select a.objuid,\n" +
            "       a.dispatch,\n" +
            "       a.model,\n" +
            "       a.drawing_no,\n" +
            "       b.jiaofuchejian,\n" +
            "       b.jieshouchejian,\n" +
            "       b.jiaofushunxu,\n" +
            "       b.quantity_of_missing_parts\n" +
            "  from mes_bzz_ptd a\n" +
            "  left join mes_bzz_ptdmx b\n" +
            "    on b.matching_doc_pk = a.objuid\n" +
            " where a.delete_tag = 1\n" +
            "   and factory_code = #{factoryCode, jdbcType = VARCHAR}\n")
    List<PtdbsDto> queryPtdbs(String factoryCode);

//    @Insert("insert into plan_goods_bind" +
//            "(ptdmx_obj, ptd_obj, paigonghao," +
//            " jixing, tuhao,jiaofuchejian," +
//            " jieshouchejian, jiaofushunxu, hegebiaoqian," +
//            " bangdingnum, bangdingren, bangdingtime," +
//            " xianghao, dingdanbianhao, tijiaojianyanren," +
//            " tijiaojianyantime, jianyanstate, jianyanren," +
//            " jianyantime, yijiaoren, yijiaotime," +
//            " peitaodanhao, yijiaodanhao, bujiandanhao," +
//            " kucun_obj, factory_id)" +
//            "values" +
//            "(#{ptdmxObj, jdbcType=VARCHAR},#{ptdObj, jdbcType=VARCHAR},#{paigonghao, jdbcType=VARCHAR}," +
//            "#{jixing, jdbcType=VARCHAR},#{tuhao, jdbcType=VARCHAR},#{jiaofuchejian, jdbcType=VARCHAR}," +
//            "#{jieshouchejian, jdbcType=VARCHAR},#{jiaofushunxu, jdbcType=VARCHAR},#{hegebiaoqian, jdbcType=VARCHAR}," +
//            "#{bangdingnum, jdbcType=NUMERIC},#{bangdingren, jdbcType=VARCHAR}, to_date(#{bangdingtime, jdbcType=DATE},'yyyy-mm-dd')," +
//            "#{xianghao, jdbcType=VARCHAR},#{dingdanbianhao, jdbcType=VARCHAR},#{tijiaojianyanren, jdbcType=VARCHAR}," +
//            "to_date(#{tijiaojianyantime, jdbcType=DATE},'yyyy-mm-dd'),#{jianyanstate, jdbcType=NUMERIC},#{jianyanren, jdbcType=VARCHAR}," +
//            "to_date(#{jianyantime, jdbcType=DATE},'yyyy-mm-dd'),#{yijiaoren, jdbcType=VARCHAR},to_date(#{yijiaotime, jdbcType=DATE},'yyyy-mm-dd')," +
//            "#{peitaodanhao, jdbcType=VARCHAR},#{yijiaodanhao, jdbcType=VARCHAR},#{bujiandanhao, jdbcType=VARCHAR}," +
//            "#{kucunObj, jdbcType=VARCHAR},#{factoryId, jdbcType=VARCHAR})")
//    int addPtjh(MesBzzPtjhDto inFoDtoParam);
//
//    @Insert("insert into plan_goods_bind" +
//            "(ptdmx_obj, ptd_obj, paigonghao," +
//            " jixing, tuhao,jiaofuchejian," +
//            " jieshouchejian, jiaofushunxu, hegebiaoqian," +
//            " bangdingnum, bangdingren, bangdingtime," +
//            " xianghao, dingdanbianhao, tijiaojianyanren," +
//            " tijiaojianyantime, jianyanstate, jianyanren," +
//            " jianyantime, yijiaoren, yijiaotime," +
//            " peitaodanhao, yijiaodanhao, bujiandanhao," +
//            " kucun_obj, factory_id)" +
//            "values" +
//            "(#{ptdmxObj, jdbcType=VARCHAR},#{ptdObj, jdbcType=VARCHAR},#{paigonghao, jdbcType=VARCHAR}," +
//            "#{jixing, jdbcType=VARCHAR},#{tuhao, jdbcType=VARCHAR},#{jiaofuchejian, jdbcType=VARCHAR}," +
//            "#{jieshouchejian, jdbcType=VARCHAR},#{jiaofushunxu, jdbcType=VARCHAR},#{hegebiaoqian, jdbcType=VARCHAR}," +
//            "#{bangdingnum, jdbcType=NUMERIC},#{bangdingren, jdbcType=VARCHAR}, to_date(#{bangdingtime, jdbcType=DATE},'yyyy-mm-dd')," +
//            "#{xianghao, jdbcType=VARCHAR},#{dingdanbianhao, jdbcType=VARCHAR},#{tijiaojianyanren, jdbcType=VARCHAR}," +
//            "to_date(#{tijiaojianyantime, jdbcType=DATE},'yyyy-mm-dd'),#{jianyanstate, jdbcType=NUMERIC},#{jianyanren, jdbcType=VARCHAR}," +
//            "to_date(#{jianyantime, jdbcType=DATE},'yyyy-mm-dd'),#{yijiaoren, jdbcType=VARCHAR},to_date(#{yijiaotime, jdbcType=DATE},'yyyy-mm-dd')," +
//            "#{peitaodanhao, jdbcType=VARCHAR},#{yijiaodanhao, jdbcType=VARCHAR},#{bujiandanhao, jdbcType=VARCHAR}," +
//            "#{kucunObj, jdbcType=VARCHAR},#{factoryId, jdbcType=VARCHAR})")
//    int addPtjhmx(MesBzzPtjhmxDto inFoDtoParam);
}
